/**
* Copyright (C) 2025-2025. Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) Facebook, Inc. and its affiliates.
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <memory>
#include <map>
#include <unordered_map>
#include "ConfigBase.h"

namespace omniruntime::config {
class Config : public ConfigBase {
public:
    template <typename T>
    using Entry = Entry<T>;

    static Entry<int32_t> ZLIB_COMPRESSION_LEVEL;
    static Entry<int32_t> ZSTD_COMPRESSION_LEVEL;
    static Entry<uint64_t> COMPRESSION_BLOCK_SIZE;
    static Entry<uint64_t> COMPRESSION_BLOCK_SIZE_MIN;
    static Entry<float> COMPRESSION_BLOCK_SIZE_EXTEND_RATIO;
    static Entry<uint32_t> COMPRESSION_THRESHOLD;
    static Entry<bool> CREATE_INDEX;
    static Entry<uint32_t> ROW_INDEX_STRIDE;
    static Entry<uint32_t> STRIPE_CACHE_SIZE;
    static Entry<uint32_t> DICTIONARY_ENCODING_INTERVAL;
    static Entry<bool> USE_VINTS;
    static Entry<float> DICTIONARY_NUMERIC_KEY_SIZE_THRESHOLD;
    static Entry<float> DICTIONARY_STRING_KEY_SIZE_THRESHOLD;
    static Entry<bool> DICTIONARY_SORT_KEYS;
    static Entry<float> ENTROPY_KEY_STRING_SIZE_THRESHOLD;
    static Entry<uint32_t> ENTROPY_STRING_MIN_SAMPLES;
    static Entry<float> ENTROPY_STRING_DICT_SAMPLE_FRACTION;
    static Entry<uint32_t> ENTROPY_STRING_THRESHOLD;
    static Entry<uint32_t> STRING_STATS_LIMIT;
    static Entry<bool> FLATTEN_MAP;
    static Entry<bool> MAP_FLAT_DISABLE_DICT_ENCODING;
    static Entry<bool> MAP_FLAT_DISABLE_DICT_ENCODING_STRING;
    static Entry<bool> MAP_FLAT_DICT_SHARE;
    static Entry<const std::vector<uint32_t>> MAP_FLAT_COLS;
    static Entry<const std::vector<std::vector<std::string>>>
    MAP_FLAT_COLS_STRUCT_KEYS;
    static Entry<uint32_t> MAP_FLAT_MAX_KEYS;
    static Entry<uint64_t> MAX_DICTIONARY_SIZE;
    static Entry<bool> INTEGER_DICTIONARY_ENCODING_ENABLED;
    static Entry<bool> STRING_DICTIONARY_ENCODING_ENABLED;
    static Entry<uint64_t> STRIPE_SIZE;
    static Entry<bool> LINEAR_STRIPE_SIZE_HEURISTICS;
    /// With this config, we don't even try the more memory intensive encodings on
    /// writer start up.
    static Entry<bool> FORCE_LOW_MEMORY_MODE;
    /// Disable low memory mode mostly for test purposes.
    static Entry<bool> DISABLE_LOW_MEMORY_MODE;
    /// Fail the writer, when Stream size is above threshold. Streams greater than
    /// 2GB will be failed to be read by Jolly/Presto reader.
    static Entry<bool> STREAM_SIZE_ABOVE_THRESHOLD_CHECK_ENABLED;
    /// Limit the raw data size per batch to avoid being forced to write oversized
    /// stripes.
    static Entry<uint64_t> RAW_DATA_SIZE_PER_BATCH;
    static Entry<bool> MAP_STATISTICS;

    static std::shared_ptr<Config> FromMap(
        const std::map<std::string, std::string> &map)
    {
        auto config = std::make_shared<Config>();
        for (const auto &pair : map) {
            config->Set(pair.first, pair.second);
        }
        return config;
    }

    Config() : ConfigBase({}, true) {}

    std::map<std::string, std::string> ToSerdeParams()
    {
        return std::map<std::string, std::string>{configs_.cbegin(), configs_.cend()};
    }
};
} // namespace facebook::velox::dwrf
